/*
 ============================================================================
 Name		: ResponseDispatcher.cpp
 Author	  : 
 Version	 : 1.0
 Copyright   :
 Description : CResponseDispatcher implementation
 ============================================================================
 */

#include "ResponseSearch.h"
#include "ResponseSearchData.h"
#include "ResponseDefinses.h"
#include "ProjectsDefines.h"
#include "ResponseMagazineItemData.h"

CResponseSearch::CResponseSearch()
{
    // No implementation required
}

CResponseSearch::~CResponseSearch()
{
    SAFE_DELETE( _data );
}

CResponseSearch* CResponseSearch::NewLC()
{
    CResponseSearch* self = new ( ELeave ) CResponseSearch( );
    CleanupStack::PushL( self );
    self->ConstructL( );
    return self;
}

CResponseSearch* CResponseSearch::NewL()
{
    CResponseSearch* self = CResponseSearch::NewLC( );
    CleanupStack::Pop( ); // self;
    return self;
}

void CResponseSearch::ConstructL()
{
    _data = CResponseSearchData::NewL( );
}

void CResponseSearch::LoadValidResponseFromXmlNode(CElement* elementResponse)
{
    _ASSERT_LOG( elementResponse != NULL );

    if( !elementResponse )
    {
        return;
    }

    CElement* elemetnResult = elementResponse->GetElement( kResponseResultNode );
    _ASSERT_LOG( elemetnResult );

    if( !elemetnResult )
    {
        return;
    }
    //_LIT( kResponseChildCateNode, "child_cate");
    //_LIT( kResponseCC_IDNode, "cc_id");
    _LIT( kResponseItemNode , "item");
    //_LIT( kResponseM_IDNode, "m_id");
    int count = elemetnResult->ElementCount( );
    for( int index = 0; index < count; index++ )
    {
        CElement* element = elemetnResult->GetElement( index );
        //_LIT( kResponseDipathcerItemNode, "items" );
        if( element && element->GetName( ) == kResponseItemNode )
        {
            CResponseMagazineItemData* itemData = ResponseMagazineItemDataParser::Parse( element );
            if( itemData )
            {
                _data->_items.Append( itemData );
            }
        }
    }
}
